﻿#ifndef TCPSOCKET_H
#define TCPSOCKET_H

#include <QTcpSocket>
#include <QQueue>
#include <QFutureWatcher>
#include <QByteArray>
#include "function.h"
#include <QTime>


class TcpSocket : public QTcpSocket
{
    Q_OBJECT
public:
    explicit TcpSocket(qintptr socketDescriptor, QObject *parent = 0);
    ~TcpSocket();
    bool handleData(const QByteArray &originaldata,MsgDatagram &msg);//用来处理数据的函数
    Function fuc;
signals:
    //void readData(const int,const QString &,const quint16,const QByteArray &);
    void sockDisConnect(const int ,const QString &,const quint16, QThread *);//NOTE:断开连接的用户信息，此信号必须发出！线程管理类根据信号计数的
public slots:
    void sentData(const QByteArray & ,const int);//发送信号的槽
    void disConTcp(int i);

signals:
    void sendeviceData(QString str);
protected slots:
    void readData();//接收数据

protected:
    QFutureWatcher<QByteArray> watcher;
    QQueue<QByteArray> datas;
//private:
public:
    quint16 CRC16(unsigned char *puchMsg, int usDataLen) const;
    bool CRCCheck(const QByteArray &originaldata) const;
    void infoCorespendent(QString &noCrCstr,MsgDatagram &msg);
public slots:
    void sendDataHandle(QString data);
    void sendDeviceData(TcpSocket* s,QString data);
private:
    qintptr socketID;
    QString phonenum; //用户手机号--更新用户状态
    QMetaObject::Connection dis;


};

#endif // TCPSOCKET_H
